package com.example.design_pattern.observer.javajdk;

import java.util.Observable;

/**
 * Created by SQ_BXZ on 2019-02-16.
 */
public class WeatherData extends Observable {

    private float temperature;
    private float humidity;
    private float pressure;

    public WeatherData() {

    }

    public void measurementsChanged(){
        // 在调用notifuObservers()之前，要先调用setChanged()来指示状态已经改变。
        setChanged();
        // 我们没有调用notifyObservers()传送数据对象，这表示我们采用的做法
        // 是“拉”,即由观察者主动请求Subject 获取信息
        notifyObservers();
    }

    public float getTemperature() {
        return temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public float getPressure() {
        return pressure;
    }

    public void setMeasurements(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }




}
